{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom:none;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <select name="statu" lay-filter="statu" id="statu">
                        <option value="">状态</option>
                        <option value="1">启用</option>
                        <option value="0">禁止</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="key" id="key" placeholder="请输入查询内容">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btns-blacks" id="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layui-btn-blue onmousemovebtns " tipsmsg="添加管理员" onclick="x_admin_show('添加管理员','{{url('admin/auth/adminadd')}}','580px','520px','95%','95%')">
                        <i class="layui-icon layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body" style="margin-top: -20px;">
            <table id="list" lay-filter="list"></table>
        </div>
    </div>
    <script type="text/html" id="imgs">
        @{{# if(d.avatar){ }}
        <div class="layer-photos-demo"><img src="@{{d.avatar}}" width="30" height="30" class="radiusinfo">&nbsp;&nbsp;@{{d.username}}</div>
        @{{# }else{  }}
        <div class="layer-photos-demo"><img src="{{asset('admin/images/head.jpg')}}" width="30" height="30" class="radiusinfo" >&nbsp;&nbsp;@{{d.username}}</div>
        @{{# } }}

    </script>
    <script type="text/html" id="open">
        <input type="checkbox" name="is_open" lay-skin="switch" lay-text="启用|禁止" value="@{{d.id}}" lay-filter="open" @{{ d.is_open == 1 ? 'checked' : '' }}  @{{d.id==1 ? 'disabled' : ''}} class="layui-btn-disabled">
    </script>
    <script type="text/html" id="addtime">
        @{{layui.util.toDateString(d.addtime*1000,'yyyy-MM-dd HH:mm:ss')}}
    </script>
    <script type="text/html" id="logintime">
        @{{layui.util.toDateString(d.logintime*1000,'yyyy-MM-dd HH:mm:ss')}}
    </script>
    <script type="text/html" id="action">
        <span>
            <button tipsmsg="编辑" class="layui-btn layui-btns-blue layui-btn-xs layuimsg" onclick="x_admin_show('编辑管理员信息','{{ url('admin/auth/adminedit') }}?id=@{{d.id}}','500px','520px','95%','95%')">
                <i class="iconfont icon-bianji2"></i>
            </button>
        </span>
        <span>
            <button tipsmsg="修改密码" class="layui-btn layui-btn-xs layui-btns-black layuimsg" onclick="x_admin_show('编辑管理员密码','{{ url('admin/auth/editpass') }}?id=@{{d.id}}','400px','260px','95%','55%')">
                <i class="iconfont icon-mima3"></i>
            </button>

        </span>
        <span>
             <button lay-event="upload" tipsmsg="上传头像" class="layui-btn layui-btns-violet layui-btn-xs layuimsg" id="head">
                <i class="iconfont icon-yunshangchuan"></i>
            </button>
        </span>
        <span>
            @{{# if(d.id==1){ }}
            <div tipsmsg="删除" class="layui-btn layui-btn-xs layui-btn-primary layui-btn-disabled layuimsg">
                @{{# }else{  }}
                <button lay-event="del" tipsmsg="删除" class="layui-btn layui-btns-red layui-btn-xs layuimsg">
                    @{{# } }}
                    <i class="iconfont icon-shanchu-tianchong"></i>
                </button>
            </div>
        </span>
    </script>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script src="{{asset('admin/js/jquery.2.1.1.min.js')}}"></script>
    <script src="{{asset('admin/js/common.js')}}"></script>
    <script>
        layui.use(['util'], function(){
            var util = layui.util;
            //固定块
            util.fixbar({
                bar1: '&#xe669'
                ,css: {right: 25, bottom: 25}
                ,bgcolor: '#393D39'
                ,click: function(type){
                    if(type === 'bar1'){
                        window.location.reload();
                    }else{

                    }
                }
            });
        });
    </script>
    <script>
        layui.use(['table','form','upload','layer'], function() {
            var table = layui.table,layer = layui.layer,form = layui.form,upload = layui.upload,$ = layui.jquery;
            var _token =  $('meta[name="csrf-token"]').attr('content');
            var adminids = "";
            var tableIn = table.render({
                elem: '#list',
                url: "{{url('admin/auth/adminlist')}}",
                text:{none: '<i class="fa fa-snowflake-o" aria-hidden="true"></i>&nbsp;暂无相关数据'},
                method: 'post',
                even: true,
                where:{_token:_token},
                title: '管理员数据信息',
                page: true,
                cols: [[
                    /*                {checkbox:true,fixed: true},*/
                    {field: 'id', title: '编号', width: 100,align: 'center',sort:true},
                    {field: 'username', title: '用户', toolbar: '#imgs', width: 200},
                    {field: 'title', title: '用户组'},
                    {field: 'loginip', title: '登录IP',sort:true},
                    {field: 'ipadress', title: '登录IP地址'},
                    {field: 'loginnum', title: '登录次数',sort:true},
                    {field: 'addtime', title: '注册时间',width:170,align: 'center',sort:true,templet: "#addtime"},
                    {field: 'logintime', title: '最后登录时间',width:170,align: 'center',sort:true,templet: "#logintime"},
                    {field:'is_open',title: '状态',width:95, align: 'center', toolbar: '#open'},
                    {width: 150,title: '操作', toolbar: '#action',fixed: 'right'}
                ]],
                limits:[{{$infomsg['configinfo']['limit']}},100,200,400,600,1000,2000],
                limit:{{$infomsg['configinfo']['limit']}},//每页默认显示的数量
                done:function(msg){
                      onmousemoves();
                      hoverOpenImg();//显示大图
                      photos();
                      uploads();
                }
            });

            //图片放大
            function hoverOpenImg(){
                var img_show = null; // tips提示
                $('td img').hover(function(){
                    var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:130px;padding:10px 5px;' />";
                    img_show = layer.tips(img, this,{
                        tips:[2, 'rgba(0,0,0,.5)']
                        ,area: ['170px']
                    });
                },function(){
                    layer.close(img_show);
                });
                $('td img').attr('style','max-width:70px');
            }

            //点击显示图片
            function photos()
            {
                layer.photos({
                    photos: 'td .layer-photos-demo'
                    ,anim: 3 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }

            table.on('tool(list)', function(obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('您确定要删除编号为： '+  data.id + ' 信息吗？', {icon: 3,skin: 'layui-layer-black',anim: 4,title:'删除'}, function(index){
                        $.post("{{url('admin/auth/admindel')}}",{id:data.id, _token:_token},function(res){
                            if(res.code===1){
                                layer.msg(res.msg);
                                tableIn.reload();
                            }else if(res.code === 0) {
                                layer.msg(res.msg);
                            }else{
                                layer.msg('你无操作权限！');
                            }
                        },'json');
                        layer.close(index);
                    });
                }else{
                    adminids = data.id;
                    //普通图片上传
                }
            });

            //上传头像
            function uploads(){
                var uploadInst = upload.render({
                    elem: 'td #head'
                    ,url: "{{url('admin/auth/upimagesinfo')}}"
                    ,auto:true
                    ,bindAction:'td #head'
                    ,before: function(obj){
                        loadings = layer.load(2, { //icon支持传入0-2
                            shade: [0.3, 'black'], //0.5透明度的灰色背景
                            content: '上传中',
                            success: function (layero) {
                                layero.find('.layui-layer-content').css({
                                    'text-indent': '-5px',
                                    'padding-top': '39px',
                                    'width': '60px'
                                });
                            }
                        });
                        this.data={_token:_token,files:'admins',adminid:adminids};//关键代码
                    }
                    /*   ,data:{_token:_token,files:'admins',adminid:adminids}*/
                    ,done: function(res){
                        layer.close(loadings);
                        if(res.code===1){
                            layer.msg(res.msg);
                            tableIn.reload();
                        }else if(res.code===0){
                            layer.msg(res.msg);
                            return false;
                        }else{
                            layer.msg('你无操作权限！');
                            return false;
                        }
                    }
                    ,error: function(){
                        layer.msg('上传失败');
                        return false;
                    }
                });
            }


            //搜索
            $('#search').on('click', function() {
                var key = $('#key').val();
                var statu = $('#statu').val();
                if($.trim(key) == '' && statu == '') {
                    layer.msg('搜索内容不能为空！');
                    return false;
                }
                tableIn.reload({
                    where: {key: key,is_open:statu,_token:_token}
                })
            });

        });

    </script>
@endsection

